# knapsack  https://docs.scipy.org/doc/scipy/tutorial/optimize.html#knapsack-problem-example
import numpy as np
from scipy import optimize
from scipy.optimize import milp
sizes  = np.array([21, 11, 15, 9, 34, 25, 41, 52])
values = np.array([22, 12, 16, 10, 35, 26, 42, 53])
bounds = optimize.Bounds(0, 1)
constraints = optimize.LinearConstraint(A=sizes, lb=0, ub=100)
res = milp(c=-values, constraints=constraints, integrality=True, bounds=bounds)
res.x
---
pip3 install scipy==1.14.1